// pages/mine/mine.js
var that,
istest=0,
  api = new (require('../../utils/api.js')),
  headimg = api.getimgurl(),
  app = getApp(),
  util = new (require('../../utils/util.js'));
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this;
    if (app.logininfo) {
      that.getdata();
    } else {
      util.setwatcher(app, this.afterlogin)
    }
  },
  afterlogin: {
    logininfo: res => {
      that.getdata();
    }
  },

  choseimg(){
    // wx.choose(res=>{
    //   console.log(res,'');
    // })

  },
  getdata(){
    wx.showLoading({
      title: '加载中',
    })
    api.getuserdetail(res=>{
      wx.hideLoading()
      if(res.data.code==0){
        wx.setStorageSync('userInfo', res.data.entity.data)
        let userInfo=res.data.entity.data
        if(istest==1){
          userInfo.litPic=''
        }
        that.setData({userInfo})
      }
    })
    let { corpWashTag ,corpBulkTag} = app.logininfo
    that.setData({corpWashTag,corpBulkTag})
  },
  to(e){
    let {url}=e.currentTarget.dataset
    if(url=="ChangePassword"){
      let {userInfo}=that.data
      if(userInfo.hasPayPwd==0){
        wx.showModal({
          content:'充值成为会员后，才会用到我哦～',
          showCancel:!1,
        })
        return;
      }
    }
    wx.navigateTo({
      url: `../${url}/${url}`,
    })
  },

  choseavatar(e){
    console.log(e,'choseavatar');

    api.uploadimg({ url: 'https://guanlizhushou.wenzengzhang.com/mpapi/user/uploadwxavatar', path:[e.detail.avatarUrl] }, {
   // api.uploadimg({ url: 'http://test_fuelunion.wenzengzhang.com/mpapi/user/uploadwxavatar', path:[e.detail.avatarUrl] }, {
      success: resarr => {
         wx.hideLoading()
         let {userInfo} = that.data
         userInfo.litPic = e.detail.avatarUrl
         that.setData({userInfo})
      //   console.log(resarr,'resarr--uploadimg');
      //  // data['picpath'] = resarr
      //   succ&&succ(resarr)
       // that.postdata(data)

        // target['imgurl'] = oldarr.concat(resarr);
        // that.confirmsubmit(target)
      }
    })

  },

  tocar(){
    // wx.setStorageSync('carnav', 1)


    wx.navigateTo({
      url: '../carmanage/carmanage',
    })
  },

  tobar(e){
    let {url}=e.currentTarget.dataset
    wx.switchTab({
      url: `../${url}/${url}`,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    that.getdata()
    // wx.showLoading({
    //   title: '加载中',
    // })
    // that.getdata()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})